//文件名：SYS_vehicleOTA
//功能：整车升级
//创建时间：2022年12月29日
//作者：dowson
//email：dowson.tseng@gmail.com
#ifndef _APP_VEHICLE_OTA__
#define _APP_VEHICLE_OTA__

#define MAX_DOWNLOAD_LIST_COUNT 16
#define MAX_DRIVER_DOWNLOAD_LIST_COUNT 1

#include "stdint.h"
#include "SYS_OTAUpgrade.h"

//文件下载当前状态
typedef enum enum_FileDownloadState {FILE_NONE=0,FILE_REQUEST=5,FILE_DLOADING,FILE_DLOADED,FILE_ERROR} eFileDownloadState;
//文件下载列表
typedef struct struct_fileDownloadList
{
    uint32_t fileLength;
    uint8_t downloadUrl[128];
    uint8_t filePtrNum;
    uint16_t downloadUrlLength;
}tFileDownloadList;

typedef struct struct_fileDownloadDriverList
{
    uint32_t fileLength;
    uint8_t downloadUrl[128];
    uint8_t filePtrNum;
    uint16_t downloadUrlLength;
}tFileDownloadDriverList;

typedef struct struct_fileDownloadListHead
{
    uint8_t nodeSize;
    uint8_t driverNodeSize;
    tFileDownloadList FileDownloadList[MAX_DOWNLOAD_LIST_COUNT];
    tFileDownloadDriverList FileDownloadDriverList[MAX_DRIVER_DOWNLOAD_LIST_COUNT];
}t_fileDownloadListHead;


//文件下载请求结构体，里面包含需要下载的目标url和存储目标文件位置
typedef struct struct_downloadFileParam
{
    uint32_t targetFileLen;
    uint8_t fileIndex;
    uint8_t fileName[8];
    uint8_t *downloadURL;
    uint16_t urlLen;
    uint8_t downloadState;
    uint32_t downloadedLen;
    uint16_t errorCode;
    t_fileDownloadListHead *fileDownloadListHead;
}t_downloadFileParam;






void AppVehicleOTAInit(void);
void Download4GDataToFile(void);
uint8_t DownloadOTAFile(tOTA_Request OTA_Request);
uint8_t DownloadDriverFile(tOTA_Request OTA_Request);
void VehicleOTAMainLoop(void);
void InUpgradeMode(void);
void OutUpgradeMode(void);
uint8_t RegisterFileDownload(t_downloadFileParam downloadParam);
eFileDownloadState checkFileDownloadState(void);
void TestFunc(void);







#endif

